local xuyi = fk.CreateSkill{
  name = "rfenghou_3d17j__xuyipeach&",
}

xuyi:addEffect("viewas", {
  pattern = "peach",
  anim_type = "support",
  mute_card = false,
  prompt = function(self, player, selected_cards, selected)
    if not player.dying then
      return "#rfenghou_3d17j__xuyipeach&-last"
    else
      return "#rfenghou_3d17j__xuyipeach&"
    end
  end,
  card_filter = Util.FalseFunc,
  view_as = function (self, player, cards)
    local card = Fk:cloneCard("peach")
    card.skillName = "rfenghou_3d17j__xuyipeach"
    return card
  end,
  before_use = function(self, player, use)
    local room = player.room
    local sources = table.filter(room:getOtherPlayers(player, false), function(source)
      return source:hasSkill("rfenghou_3d17j__xuyipeach") and not table.contains(source:getTableMark("rfenghou_3d17j__xuyipeach_banned"), player.id)
    end)
    if #sources == 0 then return xuyi.name end
    local prompt = "#rfenghou_3d17j__xuyipeach&-invoke::" .. player.id
    if not player.dying then
      prompt = "#rfenghou_3d17j__xuyipeach&-last-invoke::" .. player.id
    end
    for _, source in ipairs(sources) do
      if room:askToSkillInvoke(source, { skill_name = "rfenghou_3d17j__xuyipeach", prompt = prompt }) then
        if not player.dying then
          room:addTableMark(source, "rfenghou_3d17j__xuyipeach_banned", player.id)
          source:drawCards(source:getMaxCards() - source:getHandcardNum(), "rfenghou_3d17j__xuyipeach")
        else
          source:drawCards(1, "rfenghou_3d17j__xuyipeach")
          player:drawCards(1, "rfenghou_3d17j__xuyipeach")
        end
        return
      end
    end
    return xuyi.name
  end,
  enabled_at_play = function(self, player)
    return player:isKongcheng() and table.find(Fk:currentRoom().alive_players, function(source)
      return source ~= player and source:hasSkill("rfenghou_3d17j__xuyipeach") and not table.contains(source:getTableMark("rfenghou_3d17j__xuyipeach_banned"), player.id)
    end)
  end,
  enabled_at_response = function(self, player, response)
    return not response and player:isKongcheng() and table.find(Fk:currentRoom().alive_players, function(source)
      return source ~= player and source:hasSkill("rfenghou_3d17j__xuyipeach") and not table.contains(source:getTableMark("rfenghou_3d17j__xuyipeach_banned"), player.id)
    end)
  end
})

Fk:loadTranslationTable{
  ["rfenghou_3d17j__xuyipeach&"] = "恤遗",
  [":rfenghou_3d17j__xuyipeach&"] = "若你没有手牌，你可以令何姬选择是否：与你各摸一张牌以令你视为使用【桃】；若你未处于濒死状态，你不能再令其对你发动〖恤遗〗，其改为将手牌摸至上限。",

  ["#rfenghou_3d17j__xuyipeach&"] = "恤遗：令何姬选择是否与你各摸一张牌两次并令你视为使用【桃】",
  ["#rfenghou_3d17j__xuyipeach&-last"] = "恤遗：令何姬选择是否将手牌摸至上限并令你视为使用【桃】，你不能再令其对你发动〖恤遗〗",

  ["#rfenghou_3d17j__xuyipeach&-invoke"] = "恤遗：你可以与 %dest 各摸一张牌并令 %dest 视为使用【桃】",
  ["#rfenghou_3d17j__xuyipeach&-last-invoke"] = "恤遗：将手牌摸至上限并令 %dest 视为使用【桃】，你不能再对其发动〖恤遗〗",
}

return xuyi
